package com.st.controller;


import com.api.order.IOrderClient;
import com.st.entity.*;
import com.st.service.UserInfoService;
import com.st.interceptor.UserInfoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;



    @RequestMapping("/list")
    public UserInfo list() {
        String userIdStr = UserInfoInterceptor.getUserInfo();
        int userid = Integer.parseInt(userIdStr);
        UserInfo allById = userInfoService.findAllById(userid);

        return allById;
    }

    //修改信息
    @RequestMapping("/upData")
    public Result tNameAddUp(@RequestBody UserInfo UserInfo) {
        return userInfoService.tNameAddUp(UserInfo);
    }

    //绑定邮箱
    @RequestMapping("/regist")
    public Result regist(@RequestBody UserInfo userInfo) {
        return userInfoService.regist(userInfo);
    }

    //验证邮箱
    @RequestMapping("/check")
    public Result check(@RequestBody CodeDTO codeDTO) {
        Result check = userInfoService.check(codeDTO.getUserInfo(), codeDTO.getCode());
        return check;

    }

    //验证短信
    @RequestMapping("checkNote")
    public Result checkNote(String phone, String note) {
        return userInfoService.checkNote(phone, note);
    }

    @RequestMapping("/searchUserInfo")
    public UserInfo searchUserInfo(Integer id){
        return userInfoService.findAllById(id);
    }


    @RequestMapping("/order")
    public List<OrderAttractionsdView> findOrderAllById(){
        String userIdStr = UserInfoInterceptor.getUserInfo();
        int userid = Integer.parseInt(userIdStr);
        List<OrderAttractionsdView> orderAllById = userInfoService.findOrderAllById(userid);
        return orderAllById;
    }

}
